/*
 * Decimal.cc
 *
 *  Created on: Feb 26, 2011
 *      Author: topcoder
 */

#include "Decimal.h"
#include "math.h"

float floatValuePlusRoundCompensation(float value, unsigned int decimalPlace)
{
    unsigned int base = pow(10,decimalPlace);

    return (value + 0.5/base);
}

static float cutDecimal(float value, unsigned int decimalPlace)
{
    unsigned int base = pow(10,decimalPlace);

    return floorf(value*base)/base;
}

float Decimal::processFloatPrecision(float value, const bool rounded, \
                                     const unsigned int decimalPlace)
{
    if(rounded)
    {
        value = floatValuePlusRoundCompensation(value,decimalPlace);
    }
    return cutDecimal(value,decimalPlace);
}
